﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Threading.Tasks;
using sydfdl.TMS.Model;
using sydfdl.TMS.Tool;

namespace sydfdl.TMS.BLL
{
    public class BLLT_F_Cash
    {

        public T_Base<T_F_Cash> GetList(string xml)
        {
            T_Base<T_F_Cash> List = new T_Base<T_F_Cash>();
            #region
            SqlParameter[] para = { new SqlParameter("@para", SqlDbType.Xml, -1) };
            para[0].Value = xml;
            using (DataSet ds = SqlHelper.ExecuteProcedureToDataSet(@"P_F_GetCash", para, ""))
            {
                List<T_F_Cash> inner = new List<T_F_Cash>();
                if (ds.Tables.Count > 0)
                    List.total = ds.Tables[0].Rows.Count;
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        T_F_Cash dto = new T_F_Cash();
                        dto.CID = new Guid(dr[1].ToString());
                        dto.Num = dr[2].ToString();
                        dto.RevPayType = dr[3].ToString();
                        dto.Amount = Convert.ToDouble(dr[4].ToString());
                        dto.Remark = dr[5].ToString();
                        dto.DocNum = dr[6].ToString();
                        dto.CompanyCode = dr[7].ToString();
                        dto.ProcessBy = dr[8].ToString();
                        dto.ProcessDate = dr[9].ToString();
                        dto.ApproveBy = dr[10].ToString();
                        dto.ApproveDate = dr[11].ToString();
                        dto.CreateBy = dr[12].ToString();
                        if (!string.IsNullOrEmpty(dr[13].ToString()))
                        {
                            dto.CreateDate = Convert.ToDateTime(dr[13].ToString());
                        }
                  
                        inner.Add(dto);
                    }
                    List.data = inner;
                }
            }
            #endregion
            return List;
        }
        public string Save(params IEnumerable<T_F_Cash>[] xml)
        {
            string addXmL = EFHelp<T_F_Cash>.GetXML(xml[0]);
            string editXML = EFHelp<T_F_Cash>.GetXML(xml[1]);
            string delXML = EFHelp<T_F_Cash>.GetXML(xml[2]);
            SqlParameter[] para = { 
                                  new SqlParameter("@addXmL",SqlDbType.Xml,-1),
                                  new SqlParameter("@editXML",SqlDbType.Xml,-1),
                                  new SqlParameter("@delXML",SqlDbType.Xml,-1),
                                  new SqlParameter("@userXML",SqlDbType.Xml,-1),
                                  new SqlParameter("@ReturnValue",SqlDbType.VarChar,100)
                                  };
            para[0].Value = addXmL;
            para[1].Value = editXML;
            para[2].Value = delXML;
            para[3].Value = null;
            para[4].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(SqlHelper.tmsConn, CommandType.StoredProcedure, @"P_F_SaveCash", para);
            return (para[4].Value ?? string.Empty).ToString();
        }
    }
}
